﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Framework;
using NLBS.Urls;
using System.Xml;
using System.Web;

namespace NLBS.Provider
{
    /// <summary>
    /// Manages Url rewriting
    /// </summary>
    public class UrlReWriteProvider : NLBS.Urls.UrlReWriteProvider
    {

        static readonly object lockedObject = new object();

        public UrlReWriteProvider(LocationSet locations, string fileExpression) : base(locations, fileExpression) { }

        static UrlReWriteProvider()
        {
        }

        /// <summary>
        /// Returns the instance of the UrlReWriteProvider
        /// </summary>
        /// <returns>Instance of the UrlReWriteProvider</returns>
        public static UrlReWriteProvider Instance()
        {
            UrlReWriteProvider urp;
            if (HttpContext.Current.Cache["SiteUrls"] == null)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(HttpContext.Current.Request.PhysicalApplicationPath + "SiteUrls.config");
                UrlsData data = new UrlsData(doc, HttpContext.Current.Request.ApplicationPath);
                urp = new UrlReWriteProvider(data.LocationSet, data.LocationFilter);
                HttpContext.Current.Cache.Insert("SiteUrls", urp);
            }
            else
            {
                urp = (UrlReWriteProvider)HttpContext.Current.Cache["SiteUrls"];
            }


            return urp;
        }
    }
}
